package com.etone.smartAudit.service;

import com.etone.smartAudit.mapper.PermissionMapper;
import com.etone.smartAudit.vo.PagerVO;
import com.etone.smartAudit.vo.permission.PermissionSimpleVO;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @author: sovy
 * @date: 2020/8/5
 * @description:
 */
@AllArgsConstructor
@Service
public class PermissionService {
    private PermissionMapper permissionMapper;

    /**
     * 查询权限基本信息
     *
     * @param page     当前页
     * @param pageSize 每页大小
     * @return
     */
    public PagerVO<PermissionSimpleVO> listSimple(int page, int pageSize) {
        Page<PermissionSimpleVO> permissionSimpleVOPage = PageHelper.startPage(page, pageSize).doSelectPage(() -> {
            permissionMapper.findListSimple();
        });

        return PagerVO.of(permissionSimpleVOPage);
    }

    /**
     * 角色权限列表
     *
     * @param page     当前页
     * @param pageSize 每页大小
     * @param roleId   角色id
     * @return
     */
    public PagerVO<PermissionSimpleVO> findSimpleByRoleId(int page, int pageSize, Integer roleId) {
        Page<PermissionSimpleVO> permissionSimpleVOPage = PageHelper.startPage(page, pageSize).doSelectPage(() -> {
            permissionMapper.findSimpleByRoleId(roleId);
        });
        return PagerVO.of(permissionSimpleVOPage);
    }
}
